package com.euvmp.sdk;

import cn.hutool.core.util.IdUtil;

/**
 * @Description 发票云平台sdk统一出口
 * @Author YangZheng 328170112@qq.com
 * @Date 2020-06-29 10:50
 */
final public class YptSDK {
    private static final String URL = "https://fp.euvmp.com/api";
    /**
     * 实际用于处理sdk相关事务的单元
     */
    private final SDKUnit unit;

    private YptSDK(SDKUnit unit) {
        this.unit = unit;
    }

    /**
     * 获取sdk实例
     *
     * @param appId  用户的appId
     * @param appKey 用户的appKey
     * @return 返回sdk实例
     * @since 0.0.1
     */
    public static YptSDK getIntance(String appId, String appKey) {
        return new YptSDK(SDKUnit.getIntance(appId, appKey, URL));
    }

    /**
     * 获取sdk实例
     *
     * @param appId  用户的appId
     * @param appKey 用户的appKey
     * @param url    api服务的url
     * @return 返回sdk实例
     * @since 0.0.2
     */
    public static YptSDK getIntance(String appId, String appKey, String url) {
        return new YptSDK(SDKUnit.getIntance(appId, appKey, url));
    }

    /**
     * 发送接口调用请求
     *
     * @param sid     请求的业务唯一id，请自行生成
     * @param content 请求的主体参数,json字符串
     * @param timeout 请求的超时时间,单位毫秒
     * @return java.lang.String 响应参数
     * @author YangZheng 328170112@qq.com
     * @since 0.0.1
     */
    public String send(String sid, String content, int timeout) {
        return unit.send(sid, content, timeout);
    }

    /**
     * 发送接口调用请求
     *
     * @param sid     请求的业务唯一id，请自行生成
     * @param content 请求的主体参数,json字符串
     * @return java.lang.String 响应参数
     * @author YangZheng 328170112@qq.com
     * @since 0.0.2
     */
    public String send(String sid, String content) {
        return unit.send(sid, content, 30_000);
    }

    /**
     * 发送接口调用请求
     *
     * @param content 请求的主体参数,json字符串
     * @return java.lang.String 响应参数
     * @author YangZheng 328170112@qq.com
     * @since 0.0.2
     */
    public String send(String content) {
        return unit.send(IdUtil.fastSimpleUUID(), content, 30_000);
    }

    public static void main(String[] args) {
        try {
//            YptSDK sdk = YptSDK.getIntance("1c6eb5b175e8cfd5ed672df72845aad4", "0E6tE723SviUuexH6ujcnw");
            YptSDK sdk = YptSDK.getIntance("4d9f71861d374846a75dd359e8cefc19", "dePFZKciSjP/CIStq1omSg","http://47.99.147.85:9095/api");
            String fpxz = sdk.send(IdUtil.fastSimpleUUID(),
                                   "{" + "\"nsrsbh\": \"91340100MA2MXQ5Q6Q\"," + "\"method\": \"fpxz\"," + "\"kprqq\": \"2020-01-08\"," + "\"kprqz\": \"2020-07-01\"" + "}",
                                   3000000);
            System.out.println(fpxz);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
